package com.wang.designpattern.mediator;

public class TV extends Colleague {

    public TV(Mediator mediator, String name) {
        super(mediator, name);
        // 在创建Alarm同事对象时，将自己放入ConcreteMediator对象里的集合中
        mediator.register(name, this);
    }

    public void startTV() {
        System.out.println("startTV");
    }

    public void stopTV() {
        System.out.println("stopTV");
    }

    @Override
    public void sendMessage(int stateChange) {
        // 调用中介者对象的getMessage方法
        this.getMediator().getMessage(stateChange, this.name);
    }

    @Override
    public void receiveMessage(int stateChange) {
        if (1 == stateChange) {
            stopTV();
        } else {
            startTV();
        }
    }
}
